package com.test.rpc.test1;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
//设置自动注入HelloWorldProperties 这个类
@EnableConfigurationProperties(HelloWorldProperties.class)
public class HelloWorldAutoConfiguration {
    @Autowired
    HelloWorldProperties helloWorldProperties;
    @Bean
    @ConditionalOnMissingBean
    public HelloWorldTemplate helloWorldTemplate(){
        HelloWorldTemplate helloWorldTemplate = new HelloWorldTemplate();
        helloWorldTemplate.setUsername(helloWorldProperties.getUsername());
        return helloWorldTemplate;
    }
}
